﻿var Repository = Repository || [];

Repository.Twitter = {
    getTweets: function (query, page, maxId, callback) {
        Extension.crossDomainCall(
              'http://search.twitter.com/search.json',
              { 'q': query, 'page': page, 'include_entities': true, 'max_id': maxId },
              function (data) {
                  if (!!callback && typeof callback == 'function') {
                      callback(data);
                  }
              });
    },
    getPopularTweets: function (query, callback) {
        Extension.crossDomainCall(
              'http://search.twitter.com/search.json',
              { 'q': query, 'include_entities': true, 'result_type': 'popular', 'rpp': 100 },
              function (data) {
                  if (!!callback && typeof callback == 'function') {
                      callback(data);
                  }
              });
    },
    checkForTweets: function (query, sinceId, callback) {
        Extension.crossDomainCall(
              'http://search.twitter.com/search.json',
              { 'since_id': sinceId, 'q': query, 'include_entities': true, 'rpp': 100 },
              function (data) {
                  if (!!callback && typeof callback == 'function') {
                      callback(data);
                  }
              });
    },
    getTweetDetails: function (id, callback) {
        Extension.crossDomainCall(
              'http://api.twitter.com/1/statuses/show/' + id + '.json',
              {},
              function (data) {
                  if (!!callback && typeof callback == 'function') {
                      callback(data);
                  }
              });
    },
    getTweetReplies: function (id, callback) {
        Extension.crossDomainCall(
              'http://api.twitter.com/1/related_results/show/' + id + '.json',
              {},
              function (data) {
                  if (!!callback && typeof callback == 'function') {
                      callback(data);
                  }
              });
    },
    reply: function (id, reply, callback) {
        Extension.get('Twitter/Reply', { id: id, reply: reply }, function (data) {
            if (!!callback && typeof callback == 'function') {
                callback(data);
            }
        });
    },
    retweet: function (id, callback) {
        Extension.get('Twitter/Retweet', { id: id }, function (data) {
            if (!!callback && typeof callback == 'function') {
                callback(data);
            }
        });
    },
    favorite: function (id, callback) {
        Extension.get('Twitter/Favorite', { id: id }, function (data) {
            if (!!callback && typeof callback == 'function') {
                callback(data);
            }
        });
    },
    delete: function (id, callback) {
        Extension.get('Twitter/Delete', { id: id }, function (data) {
            if (!!callback && typeof callback == 'function') {
                callback(data);
            }
        });
    }
};